package cn.jdy.plugins.wap;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.plugins.entity.GuseBook;
import cn.jdy.plugins.service.CompanyContextService;
import cn.jdy.plugins.service.CompanyService;
import cn.jdy.plugins.service.GuseBookService;

/**
 * 加盟留言控制类
 *
 * @author zhaiguangtao
 */
@Controller
@RequestMapping("/gusebook")
public class GuseBookCtrl extends BaseCtrl {

	@Autowired
	private GuseBookService guseBookService;
	@Autowired
	private CompanyService companyService;
	@Autowired
	private CompanyContextService companyContextService;

	/**
	 * 初始化公共在线留言页面
	 * @param gusebook
	 * @return
	 */
	@RequestMapping("/{companyId}")
	public ModelAndView initPub(@PathVariable String companyId) {
		ModelAndView mv = new ModelAndView();
		mv.addObject("companyId",companyId);
		mv.setViewName(super.t + "/companyContext/lealwords");
		return mv;
	}
	
	/**
   * 加盟留言
   * @return
   */
  @RequestMapping("/lealword")
  @ResponseBody
  public Map<String, Object> saveLealwordajax(GuseBook gusebook) {
    Map<String, Object> jsonMap = new HashMap<String, Object>();
    try {
      gusebook.setId(null);
      gusebook.setIp(request.getRemoteAddr());
      gusebook.setGusetime(new Date());
      guseBookService.save(gusebook);
      jsonMap.put("status", 200);
    } catch (Exception e) {
      jsonMap.put("status", 500);
      BaseLog.e(this.getClass(), "保存留言信息失败", e);
    }
    return jsonMap;
  }
	 
}
